# -*- coding: utf-8 -*-
# @Author: Tim Liu
# @Date: 2025-01-08
# @Last Modified by: Cursor
# @Last Modified time: 2025-01-08

# @Description: document processor dispatcher registry

from crewplus.apps.rag.schemas.source_type import SourceType

from crewplus.apps.rag.processor_dispatcher import DocumentProcessorDispatcher
from crewplus.apps.rag.processors.html_processor import HtmlDocumentProcessor
from crewplus.apps.rag.processors.pdf_processor import PdfDocumentProcessor
from crewplus.apps.rag.processors.audio_processor import AudioDocumentProcessor
from crewplus.apps.rag.processors.image_processor import ImageDocumentProcessor

from crewplus.apps.rag.processors.doc_processor import DocDocumentProcessor
from crewplus.apps.rag.processors.excel_processor import ExcelDocumentProcessor
from crewplus.apps.rag.processors.ppt_processor import PPTDocumentProcessor

# Global dispatcher registry
dispatcher_registry = {}

# Function to initialize default processors
def initialize_default_processors(dispatcher: DocumentProcessorDispatcher):
    """Initialize default document processors for the dispatcher."""
    dispatcher.register("html", SourceType.WEBSITE, HtmlDocumentProcessor())
    dispatcher.register("pdf", SourceType.UPLOAD, PdfDocumentProcessor())
    dispatcher.register("audio", SourceType.UPLOAD, AudioDocumentProcessor())
    dispatcher.register("image", SourceType.UPLOAD, ImageDocumentProcessor())
    dispatcher.register("pdf", SourceType.SHAREPOINT, PdfDocumentProcessor())
    dispatcher.register("image", SourceType.SHAREPOINT, ImageDocumentProcessor())
    dispatcher.register("doc", SourceType.SHAREPOINT, DocDocumentProcessor())
    dispatcher.register("ppt", SourceType.SHAREPOINT, PPTDocumentProcessor())
    dispatcher.register("excel", SourceType.SHAREPOINT, ExcelDocumentProcessor())


# Create a single dispatcher instance for default processors
default_dispatcher = DocumentProcessorDispatcher()
initialize_default_processors(default_dispatcher)

# Store the default dispatcher in the global registry
dispatcher_registry['default'] = default_dispatcher